package com.xinke.module.system.convert.post;

import com.xinke.component.common.util.collection.CollectionUtils;
import com.xinke.component.common.util.object.BeanUtils;
import com.xinke.module.system.model.entity.user.AdminUserDO;
import com.xinke.module.system.model.entity.user.DeptDO;
import com.xinke.module.system.model.entity.user.PostDO;
import com.xinke.module.system.model.vo.user.AdminUserRespVO;
import com.xinke.module.system.model.vo.user.PostRespVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;

@Mapper
public interface PostConvert {
    PostConvert INSTANCE = Mappers.getMapper(PostConvert.class);

    default List<PostRespVO> convertList(List<PostDO> list, Map<Long, DeptDO> deptMap) {
        return CollectionUtils.convertList(list, post -> convert(post, deptMap.get(post.getDeptId())));
    }
    default PostRespVO convert(PostDO post, DeptDO dept) {
        PostRespVO postVO = BeanUtils.toBean(post, PostRespVO.class);
        if (dept != null) {
            postVO.setDeptName(dept.getDeptName());
        }
        return postVO;
    }
}
